import java.util.ArrayList;

public class StudentUtil {
    //需求：定义一个集合，用来存储三个学生对象
    //学生类的属性为：name。age。gender
    //定义一个工具类，用来获取集合中最大的学生年龄

    private String name;
    private int age;
    private String gender;

    public StudentUtil() {
    }

    public StudentUtil(String name, int age, String gender) {
        this.name = name;
        this.age = age;
        this.gender = gender;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }


    public static int maxAge(ArrayList<StudentUtil> list) {
        if (!list.isEmpty()){

            int maxAge = list.getFirst().getAge();
            for (int i = 1; i < list.size(); i++) {
                if (list.get(i).getAge() > maxAge) {
                    maxAge = list.get(i).getAge();
                }
            }
            return maxAge;
        } else {
            return 0;
        }
    }


    public static void main(String[] args) {
        ArrayList<StudentUtil> list = new ArrayList<>();
        StudentUtil s1 = new StudentUtil("Alice", 20, "Female");
        StudentUtil s2 = new StudentUtil("Bob", 22, "Male");
        StudentUtil s3 = new StudentUtil("Charlie", 19, "Male");
        list.add(s1);
        list.add(s2);
        list.add(s3);
        maxAge(list);
        System.out.println("The maximum age is: " + maxAge(list)); // Output: The maximum age is: 22
    }
}
